﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Threading;
using System.Threading;
using EnvDTE;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio;
using System.Collections;

namespace UWCSE.CompleterVSPackage
{
    // From http://sachabarber.net/?p=418
    /// <summary>
    /// WPF Threading extension methods
    /// </summary>
    public static class WPFControlThreadingExtensions
    {
        #region Public Methods
        /// <summary>
        /// A simple WPF threading extension method, to invoke a delegate
        /// on the correct thread if it is not currently on the correct thread
        /// Which can be used with DispatcherObject types
        /// </summary>
        /// <param name="disp">The Dispatcher object on which to do the Invoke</param>
        /// <param name="dotIt">The delegate to run</param>
        /// <param name="priority">The DispatcherPriority</param>
        public static void InvokeIfRequired(this Dispatcher disp,
            Action dotIt, DispatcherPriority priority)
        {
            if (disp.Thread != System.Threading.Thread.CurrentThread)
            {
                disp.BeginInvoke(priority, dotIt);
            }
            else
                dotIt();
        }
        #endregion
    }

    static class EnumerableUtil
    {
        public static IEnumerable<T> OfType<T>(this IEnumerable xs)
        {
            foreach (var x in xs)
            {
                yield return (T)x;
            }
        }
    }
}
